package m.jclecai.com.utils;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Created by hp on 2017/5/5.
 */

public class BonusUtils {

    private static final String TAG = "一一一一一一一一一一一一一一一一";
    private static List<Integer> result; //计算后的奖金


    public static List<Integer> bonusCalculation(Map<Integer, Boolean> selectMap, int currentPosition) {
        int top = 0;
        int bottom = 0;
        result = new LinkedList<>();

        //从map集合中取出选中的号码到list集合
        List<Integer> ls = new LinkedList<>();
        for (Map.Entry<Integer, Boolean> entry : selectMap.entrySet()) {
            if (entry.getValue()) {
                ls.add(entry.getKey());
            }
        }
        //选中的号码是复数则对集合进行排序后取首位的奖金值进行返回
        if (ls.size() > 1) {
            Collections.sort(ls);
            top = ls.get(0);
            int computeTop = compute(top, currentPosition);
            result.add(computeTop);
            bottom = ls.get(ls.size() - 1);
            int computeBottom = compute(bottom, currentPosition);
            result.add(computeBottom);
        } else if (ls.size() == 1) {
            top = ls.get(0);
            int compute = compute(top, currentPosition);
            result.add(compute);
        }

        //去除重复数据并排序
        LinkedHashSet set = new LinkedHashSet();
        set.addAll(result);
        result.clear();
        result.addAll(set);
        Collections.sort(result);
        return result;
    }

    //和值奖金计算
    private static int compute(int number, int currentPosition) {
        switch (currentPosition) {
            case 0:
                if (number == 3 || number == 18) {
                    return 240;
                } else if (number == 4 || number == 17) {
                    return 80;
                } else if (number == 5 || number == 16) {
                    return 40;
                } else if (number == 6 || number == 15) {
                    return 25;
                } else if (number == 7 || number == 14) {
                    return 16;
                } else if (number == 8 || number == 13) {
                    return 12;
                } else if (number == 9 || number == 12) {
                    return 10;
                } else if (number == 10 || number == 11) {
                    return 9;
                }
                break;
            case 1:
                if (number == 9999) {
                    return 40;
                } else {
                    return 240;
                }
            case 2:
                if (number == 11 || number == 22 || number == 33 || number == 44 || number == 55 || number == 66) {
                    return 15;
                } else {
                    return 80;
                }
            case 3:
                if (number == 9999) {
                    return 10;
                } else {
                    return 40;
                }
            case 4:
                return 9;
        }
        return 0;
    }

}
